# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Médéric Boquien <mboquien@free.fr>

_pkg=astropy
pkgname=python-${_pkg}
pkgver=5.2.2
pkgrel=2
pkgdesc="Common core package for Astronomy"
arch=(loong64 x86_64)
url="https://www.astropy.org/"
license=(BSD)
depends=(python cfitsio expat wcslib python-numpy python-pyerfa python-yaml python-packaging)
makedepends=(python-build python-installer python-wheel python-setuptools-scm python-extension-helpers cython)
optdepends=('python-matplotlib: plotting functionality astropy.visualization'
            'python-scipy: variety of features in several modules'
            'python-certifi'
            'python-dask'
            'python-h5py: read/write Table objects from/to HDF5 files'
            'python-beautifulsoup4: read Table objects from HTML files'
            'python-html5lib: read Table objects from HTML files using the pandas reader'
            'python-bleach: sanitize text when disabling HTML escaping in the Table HTML writer'
            'libxml2: validates VOTABLE XML files'
            'python-pandas: convert Table objects from/to pandas DataFrame objects'
            'python-sortedcontainers: faster SCEngine indexing engine with Table'
            'python-pytz: specify and convert between timezones'
            #'python-jplephem: retrieves JPL ephemeris of Solar System objects'
            'python-setuptools: discovery of entry points which are used to insert fitters into astropy.modeling.fitting'
            'python-mpmath: ‘kraft-burrows-nousek’ interval in poisson_conf_interval'
            #'python-asdf: serialization of various Astropy classes into a portable, hierarchical, human-readable representation'
            'python-bottleneck: improves the performance of sigma-clipping and other functionality that may require computing statistics on arrays with NaN values'
            'python-pyarrow: read/write Table objects from/to Parquet files'
            'python-fsspec: opening remote and cloud-hosted FITS files')
#checkdepends=(python-pytest python-pytest-xdist python-hypothesis)
source=(https://files.pythonhosted.org/packages/source/a/${_pkg}/${_pkg}-${pkgver}.tar.gz)
sha256sums=('e6a9e34716bda5945788353c63f0644721ee7e5447d16b1cdcb58c48a96b0d9c')

build() {
  cd ${_pkg}-${pkgver}
  ASTROPY_USE_SYSTEM_ALL=1 python -m build --wheel --no-isolation --skip-dependency-check
}

# Tests require a lot of unpackaged pytest modules
#check() {
#  cd ${_pkg}-${pkgver}
#  sed "s|addopts = --color=yes --doctest-rst|addopts = --color=yes|" -i setup.cfg
#  local python_version=$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')
#  PYTHONPATH="${PWD}"/build/lib.linux-${CARCH}-cpython-${python_version/./}/ pytest -vv --color=yes astropy
#}

package() {
  cd ${_pkg}-${pkgver}
  ASTROPY_USE_SYSTEM_ALL=1 python -m installer --destdir="${pkgdir}" dist/*.whl
  install -Dm644 LICENSE.rst -t "${pkgdir}"/usr/share/licenses/$pkgname/
}
